home *** CD-ROM | disk | FTP | other *** search
- /* token.c is the shell of the token handling routine, which is filled
- * in with the routines executed when an action described by a token entry
- * is found.
- */
-
- /*
- Copyright Cornell University 1986. All rights are reserved.
-
- */
-
- #include <em.h>
-
- #include <menudefs.h>
- #include <rcodes.h>
- #include <h19.h>
- #include <3270.h>
- #include <macdefs.h>
- #include <resdefs.h>
-
-
- char scrapzeroed; /* has scrap been zeroed yet? */
- short intoken_service; /* we don't handle reentrant calls, error() can be fatal */
-
- token_service()
- {
- struct token * theact;
- struct winds ** conp = conns;
- struct winds * conend = &conp[conncount];
- register struct winds * twp;
- extern short asciiflush;
-
- if (intoken_service)
- return;
- intoken_service = TRUE;
-
- /* TODO MULTI go through window list to see who needs service */
- while (conp < conend) {
- twp = *conp++;
- if (twp == NULL)
- continue;
-
- if (twp->q_cnt == 0 || twp->delaytokens)
- /* no input tokens waiting, or we should hold tokens for this window... */
- continue;
-
- getcontext(twp);
- while (!twp->delaytokens && twp->q_cnt > 0) {
- theact = getaction();
- if ((*twp->dotoken)(theact)) {
- ungetaction(theact);
- break;
- }
- }
- if (twp->emwindow) {
- /* if the session has a window, fix the macro flag */
- if (!twp->macroexecuting) {
- if (twp->q_cnt > 0) {
- /* invert the macro flag */
- twp->macroexecuting = TRUE;
- /* InvalRect(&twp->macrorect);
- */
- showmacroflag();
- /* show inverse macro flag to indicate stuff left on
- queue which can still be cancelled... */
- }
- }
- else {
- if (twp->q_cnt <= 0) {
- /* reset the flag */
- twp->macroexecuting = FALSE;
- if (emdp->dokeymacros)
- showmacroflag();
- else
- clrmacroflag();
- /* InvalRect(&twp->macrorect);
- */
- }
- }
- }
- if (asciiflush) {
- /* flush the output buffers if called for, only need with ascii */
- asciiflush = FALSE;
- (*twp->putflush)();
- }
- twp->modflg = modflg; /* must update in case state changed */
- }
- intoken_service = FALSE;
- }
-
-
- /* preserves the current context over a call to token_service() */
-
- bkrd_token_service()
- {
- struct winds * oemdp;
-
- oemdp = emdp;
- token_service();
-
- getcontext(oemdp); /* restore context, since it might have changed */
- }
-
- /* reset the flag that holds token interpretation */
-
- resumetokens(twp)
- struct winds * twp;
- {
- twp->delaytokens = FALSE;
- }
-
-
- /* abort processing after match failure */
-
- abortmatch(twp)
- struct winds * twp;
- {
- struct winds * oemdp;
-
- oemdp = emdp;
- emdp = twp; /* fix the data context for token processing */
-
- emdp->delaytokens = FALSE;
- flushtokenmatch();
-
- emdp = oemdp;
- }
-
-
- /* the standard token handler, for tokens any emulator will need to handle */
-
- stdtoken(tkptr)
- struct token *tkptr;
- {
- struct token *wtoken;
-
- switch (tkptr->class) {
- case RSLT_SCOPY: {
- rlincopy(tkptr->entry);
- break;
- }
- case RSLT_DELAY: {
- /* delay input for # of seconds specified by token entry */
- emdp->delaytokens = TRUE;
- tm_set((int) tkptr->entry, resumetokens, emdp, emdp->token_tm);
- break;
- }
- case RSLT_MATCH: {
- /* wait until a match is found in the input stream */
- emdp->delaytokens = TRUE;
- emdp->matchinput = TRUE;
- tokenloop(-1); /* establish eternal loop */
- if (tkptr->entry != 255)
- /* time out on wait unless user specifies 255 */
- tm_set((int) tkptr->entry, abortmatch, emdp, emdp->token_tm);
- break;
- }
- case RSLT_EMC: {
- /* emulator action key */
- switch(tkptr->entry) {
- case EM_FILLCLOSE: {
- fillwindclose();
- break;
- }
- case EM_RESTORE: {
- /* restore line 25 -- used by hostconncomplete() */
- reset25(emdp);
- break;
- }
- case EM_HIDE: {
- emdp->emdisable = TRUE;
- /* make sure cursor is visible */
- SetCursor(&arrow);
- showcursor();
- break;
- }
- case EM_ALTMACRO: {
- emdp->keyaltset = TRUE;
- /* InvalRect(&emdp->dubshiftrect); */
- if (emdp->dokeymacros)
- showaltmacro();
- break;
- }
- case EM_NORMMACRO: {
- emdp->keyaltset = FALSE;
- /* InvalRect(&emdp->dubshiftrect); */
- if (emdp->dokeymacros)
- clraltmacro();
- break;
- }
- case EM_CLOSE: {
- /* close the session */
- docloseconn();
- break;
- }
- case EM_SHOW: {
- emdp->emdisable = FALSE;
- /* (*emdp->screen_upd)(); */
- break;
- }
- #ifdef USETEXTWINDOWS
- case EM_EDIT: {
- selectwindow(emdp->textwindow);
- ShowWindow(emdp->textwindow);
- break;
- }
- case EM_TERM: {
- selectwindow(emdp->emwindow);
- break;
- }
- case EM_LITERAL: {
- if (emdp->emliteral)
- emdp->emliteral = FALSE;
- else
- emdp->emliteral = TRUE;
- /* set the ASCII emulators to pass all characters... */
- break;
- }
- case EM_TRYDSDRAW: {
- /* toggle fast drawing mode */
- trydsdraw = !trydsdraw;
- testdsall();
- break;
- }
- case EM_TRACK: {
- /* toggle sending of cursor positioning sequences with mouse */
- emdp->notrackcurs = !emdp->notrackcurs;
- break;
- }
- #endif
- default:
- entryerr(tkptr);
- }
- break;
- }
- case RSLT_LOOP: {
- /* emulator action key */
- if (tkptr->entry == 255)
- /* loop forever */
- tokenloop(-1);
- else
- tokenloop(tkptr->entry);
- break;
- }
- case RSLT_FILE: {
- switch (tkptr->entry) {
- case RF_SAVE:
- case RF_SAVEAS:
- case RF_APPEND:
- case RF_APPENDTO: {
- savetext(tkptr->entry);
- if (edresetselect)
- selreset(emdp);
-
- break;
- }
- case RF_PRINTDRAFT: {
- printtext(tkptr->entry, FALSE);
- if (edresetselect)
- selreset(emdp);
-
- break;
- }
- case RF_PRINTTEXT:
- case RF_PRINTSCREEN:
- case RF_PRINTSCRAP: {
- QDprinttext(tkptr->entry, FALSE);
- if (edresetselect)
- selreset(emdp);
-
- break;
- }
- case RF_NAME: {
- #ifdef RF_NAMEDONE
- int namecount = 0;
-
- while (twp->q_cnt > 0) {
-
- theact = getaction();
- if ((*twp->dotoken)(theact)) {
- ungetaction(theact);
- break;
- }
- }
- #endif
- break;
- }
- }
- break;
- }
- case RSLT_SEL1: {
- emdp->nselystart = tkptr->entry;
- break;
- }
- case RSLT_SEL2: {
- emdp->nselxstart = tkptr->entry;
- break;
- }
- case RSLT_SEL3: {
- emdp->nselyend = tkptr->entry;
- break;
- }
- case RSLT_SEL4:
- {
- emdp->nselxend = tkptr->entry;
- /* a selection has presumably now been defined */
-
- selreset(emdp);
- selset(emdp->nselystart, emdp->nselxstart, emdp->nselyend, emdp->nselxend);
-
- selinvert(emdp);
- emdp->selrectvis = TRUE;
-
- emdp->nselystart = 0;
- emdp->nselxstart = 0;
- emdp->nselyend = 0;
- emdp->nselxend = 0;
- break;
- }
- case RSLT_WIND: {
- /* select the window corresponding to the ith entry in the menu */
- windmenuselect((short) tkptr->entry);
- break;
- }
- default: {
- return(-1);
- }
- }
- return(0);
- }
-
-
- stdedit(action)
- unsigned char action;
- {
- long len;
-
- switch (action) {
- case ED_STDMODE: {
- emdp->copytable = FALSE;
- break;
- }
- case ED_TABLEMODE: {
- /* elide tabs */
- emdp->copytable = TRUE;
- break;
- }
- case ED_WORDSELECT: {
- /* select the word around the cursor position */
- wordselect();
- break;
- }
- case ED_SELRESET: {
- if (emwindow) {
- selreset(emdp);
- }
- break;
- }
- case ED_SELALL: {
- if (emwindow) {
- #ifdef DOTEXTEDIT
- /* macros should probably not muck with the TE window */
- if (emdp->edit) {
- tesetsel( (long) 0, (long) (*emdp->texthand)->teLength, emdp->texthand);
- }
- else {
- #endif
- selreset(emdp);
- selset(0, 0, 24, 0);
- selinvert(emdp);
- emdp->selrectvis = TRUE;
- #ifdef DOTEXTEDIT
- }
- #endif
- }
- break;
- }
- case ED_CUT: {
- #ifdef DOTEXTEDIT
- if (emdp->edit) {
- textwcut(emdp);
- break;
- }
- #endif
- break;
- }
- #ifdef USETEXTWINDOWS
- case ED_APPEND: {
- /* append selection to text window */
- Ptr copyp;
-
- if ((len = getselection(©p)) == 0) {
- break;
- }
- if (!memtest(len, copyerr)) {
- /* not enough memory for operation */
- DisposPtr(copyp);
- break;
- }
- textwappend(copyp, len);
- DisposPtr(copyp);
-
- if (edresetselect)
- selreset(emdp);
-
- break;
- }
- #else
- /* when using the Clipboard you must hit SystemEdit() */
- case ED_APPEND:
- #endif
- case ED_COPY:
- {
- /* copy the whole screen into the system scrap */
- Ptr copyp;
- #ifdef DOTEXTEDIT
- if (emdp->edit) {
- /* we're in text editor, do it the easy way TODO should support append */
- textwcopy(emdp);
- break;
- }
- #endif
- if (mfpresent)
- /* make sure mf updates all client's scrap info */
- SystemEdit(EDCOPY - 1);
-
- if (!scrapzeroed) {
- /* zero the scrap the first time through */
- scrapzeroed = TRUE;
- scrapzero();
- }
-
- if (action == ED_COPY)
- scrapzero();
- /* if scrap is not zeroed, putscrap will append */
-
- if ((len = getselection(©p)) == 0) {
- break;
- }
-
- if (!memtest(len, copyerr)) {
- /* not enough memory for operation */
- DisposPtr(copyp);
- break;
- }
- #ifdef USETEXTWINDOWS
- PutScrap(len, 'TEXT', copyp);
- #else
- puttextscrap(copyp, len);
- #endif
- DisposPtr(copyp);
-
- if (edresetselect)
- selreset(emdp);
-
- break;
- }
- case ED_PASTE: {
- #ifdef DOTEXTEDIT
- if (emdp->edit) {
- textwpaste(emdp);
- }
- else
- #endif
- return(TRUE);
- break;
- }
- default:
- return(TRUE);
- }
- return(FALSE);
- }
-
-
- /* token error reporting routines */
- /* report an error in the class */
-
- classerr(tkptr)
- struct token * tkptr;
- {
- char badclassstr[140];
-
- sprintf(badclassstr, "Command '%c%c': Unknown command class '%c' (decimal %u)", tkptr->class, tkptr->entry, tkptr->class, (int) tkptr->class);
- SetDAFont((short) OURCHICAGO);
- error(badclassstr);
- SetDAFont((short) systemFont);
- }
-
- /* report an error in the entry */
-
- entryerr(tkptr)
- struct token * tkptr;
- {
- char badclassstr[140];
-
- sprintf(badclassstr, "Command '%c%c': Unknown command entry '%c' (decimal %u)", tkptr->class, tkptr->entry, tkptr->entry, (int) tkptr->entry);
- SetDAFont((short) OURCHICAGO);
- error(badclassstr);
- SetDAFont((short) systemFont);
- }
-
-
- wordselect()
- {
- register char * chp;
- char * thep;
- register char * linestart;
- register char * lineend;
- register unsigned char thechar;
- short theypos;
- short thexpos;
- short startypos; /* x,y starting and ending positions. y = column */
- short startxpos;
- short endypos;
- short endxpos;
-
- selreset(emdp);
- if (emdp->ibm_mode) {
- thep = chp = cursor_ptr;
-
- startypos = (chp - scr_map) / emdp->linelength;
- linestart = scr_map + (startypos * emdp->linelength);
- lineend = linestart + emdp->linelength;
-
- while (chp >= emdp->scr_map && chp >= linestart) {
- /* find a space at the left end */
- thechar = *chp;
- if (thechar < ATTR || thechar == IBMNULL || thechar == ' ')
- break;
- --chp;
- }
- chp++;
- startxpos = chp - (scr_map + (startypos * emdp->linelength));
-
- chp = thep;
- while (chp < emdp->smap_end && chp < lineend) {
- /* find a space at the right end */
- thechar = *chp;
- if (thechar < ATTR || thechar == IBMNULL || thechar == ' ')
- break;
- chp++;
- }
- endypos = (chp - emdp->scr_map) / emdp->linelength;
- endxpos = (chp - (scr_map + (endypos * emdp->linelength)));
- }
- else {
- thep = chp = charp;
-
- startypos = (chp - &emdp->charr[0]) / emdp->linelength;
- linestart = &emdp->charr[0] + (startypos * emdp->linelength);
- lineend = linestart + emdp->linelength;
-
- while (chp >= &emdp->charr[0] && chp >= linestart) {
- if (*chp == ' ')
- break;
- --chp;
- }
- chp++;
- startxpos = chp - (&emdp->charr[0] + (startypos * emdp->linelength));
-
- chp = thep;
- while (chp < emdp->charrend && chp < lineend) {
- if (*chp == ' ')
- break;
- chp++;
- }
- endypos = (chp - &emdp->charr[0]) / emdp->linelength;
- endxpos = chp - (&emdp->charr[0] + (endypos * emdp->linelength));
- }
- /* now invert the selection */
- if (startypos == endypos && startxpos >= endxpos)
- /* no selection */
- return;
-
- selset(startypos, startxpos, endypos, endxpos);
- selinvert(emdp);
- emdp->selrectvis = TRUE;
- }
-
-